

import 'package:flutter/material.dart';

class ResizableColumnWidget extends StatefulWidget {
  Widget leftChild;
  Widget rightChild;


  ResizableColumnWidget(this.leftChild, this.rightChild);

  @override
  State<ResizableColumnWidget> createState() => _ResizableColumnWidgetState();
}

class _ResizableColumnWidgetState extends State<ResizableColumnWidget> {
  double _offset = -500;

  @override
  Widget build(BuildContext context) {
    return LayoutBuilder(builder: (context, constraints) {
      const minWidth = 50;
      const dividerWidth = 8;
      final halfWidth = constraints.maxWidth * 0.5;

      if(halfWidth+_offset<minWidth){
        _offset = minWidth-halfWidth;
      }if(halfWidth-_offset<minWidth){
        _offset = halfWidth-minWidth;
      }
      return Row(
        children: [
          Container(
            width: halfWidth + _offset - 8,
            child: widget.leftChild,
          ),
          DraggableDivider((dx) {
            setState(() {
              _offset += dx;
            });
          }),
          Container(
            width: halfWidth - _offset - 8,
            child: widget.rightChild,
          ),
        ],
      );
    });
  }
}

class DraggableDivider extends StatelessWidget {
  Function(double v) dragupdate;

  DraggableDivider(this.dragupdate);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onHorizontalDragUpdate: (d) {
        dragupdate.call(d.delta.dx);
      },
      child: MouseRegion(
        cursor: SystemMouseCursors.resizeColumn,
        child: VerticalDivider(
          thickness: 4,
          color: Colors.red,
        ),
      ),
    );
  }
}
